LOCAL_PATH := $(call my-dir)

MY_APP_JNI_ROOT := $(LOCAL_PATH)
MY_APP_PRJ_ROOT := $(MY_APP_JNI_ROOT)/..

ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
MY_APP_FFMPEG_OUTPUT_PATH := $(MY_APP_PRJ_ROOT)/jniLibs/ffmpeg-armv7a
MY_APP_SDL2_OUTPUT_PATH := $(MY_APP_PRJ_ROOT)/jniLibs/armeabi-v7a
endif
ifeq ($(TARGET_ARCH_ABI),armeabi)
MY_APP_FFMPEG_OUTPUT_PATH := $(MY_APP_PRJ_ROOT)/jniLibs/ffmpeg-armv5
endif
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
MY_APP_FFMPEG_OUTPUT_PATH := $(MY_APP_PRJ_ROOT)/jniLibs/ffmpeg-arm64
endif
ifeq ($(TARGET_ARCH_ABI),x86)
MY_APP_FFMPEG_OUTPUT_PATH := $(MY_APP_PRJ_ROOT)/jniLibs/ffmpeg-x86
MY_APP_SDL2_OUTPUT_PATH := $(MY_APP_PRJ_ROOT)/jniLibs/x86
endif
ifeq ($(TARGET_ARCH_ABI),x86_64)
MY_APP_FFMPEG_OUTPUT_PATH := $(MY_APP_PRJ_ROOT)/jniLibs/ffmpeg-x86_64
endif

MY_APP_FFMPEG_INCLUDE_PATH := $(MY_APP_PRJ_ROOT)/jni/include
MY_APP_SDL2_INCLUDE_PATH := $(MY_APP_PRJ_ROOT)/jni/include

include $(CLEAR_VARS)
LOCAL_MODULE    := avcodec
LOCAL_SRC_FILES := $(MY_APP_FFMPEG_OUTPUT_PATH)/libavcodec.a
LOCAL_EXPORT_C_INCLUDES := $(MY_APP_FFMPEG_INCLUDE_PATH)
LOCAL_C_INCLUDES += $(MY_APP_FFMPEG_INCLUDE_PATH)
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := avformat
LOCAL_SRC_FILES := $(MY_APP_FFMPEG_OUTPUT_PATH)/libavformat.a
LOCAL_EXPORT_C_INCLUDES := $(MY_APP_FFMPEG_INCLUDE_PATH)
LOCAL_C_INCLUDES += $(MY_APP_FFMPEG_INCLUDE_PATH)
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := swscale
LOCAL_SRC_FILES := $(MY_APP_FFMPEG_OUTPUT_PATH)/libswscale.a
LOCAL_EXPORT_C_INCLUDES := $(MY_APP_FFMPEG_OUTPUT_PATH)/include
LOCAL_C_INCLUDES += $(MY_APP_FFMPEG_INCLUDE_PATH)
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := avutil
LOCAL_SRC_FILES := $(MY_APP_FFMPEG_OUTPUT_PATH)/libavutil.a
LOCAL_EXPORT_C_INCLUDES := $(MY_APP_FFMPEG_INCLUDE_PATH)
LOCAL_C_INCLUDES += $(MY_APP_FFMPEG_INCLUDE_PATH)
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := avfilter
LOCAL_SRC_FILES := $(MY_APP_FFMPEG_OUTPUT_PATH)/libavfilter.a
LOCAL_EXPORT_C_INCLUDES := $(MY_APP_FFMPEG_INCLUDE_PATH)
LOCAL_C_INCLUDES += $(MY_APP_FFMPEG_INCLUDE_PATH)
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := swresample
LOCAL_SRC_FILES := $(MY_APP_FFMPEG_OUTPUT_PATH)/libswresample.a
LOCAL_EXPORT_C_INCLUDES := $(MY_APP_FFMPEG_INCLUDE_PATH)
LOCAL_C_INCLUDES += $(MY_APP_FFMPEG_INCLUDE_PATH)
include $(PREBUILT_STATIC_LIBRARY)

###########################
# SDL2
###########################
#include $(CLEAR_VARS)
#LOCAL_MODULE := SDL2
#LOCAL_ARM_MODE=arm

#LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/SDL2
#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)

#LOCAL_SRC_FILES := \
#	$(subst $(LOCAL_PATH)/,, \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/audio/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/audio/android/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/audio/dummy/*.c) \
#	$(LOCAL_PATH)/src/SDL2/atomic/SDL_atomic.c \
#	$(LOCAL_PATH)/src/SDL2/atomic/SDL_spinlock.c.arm \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/core/android/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/cpuinfo/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/dynapi/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/events/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/file/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/haptic/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/haptic/dummy/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/joystick/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/joystick/android/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/loadso/dlopen/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/power/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/power/android/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/filesystem/android/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/render/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/render/*/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/stdlib/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/thread/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/thread/pthread/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/timer/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/timer/unix/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/video/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/video/android/*.c) \
#	$(wildcard $(LOCAL_PATH)/src/SDL2/test/*.c))

#LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES
#LOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -llog -landroid
#include $(BUILD_SHARED_LIBRARY)
###########################
# SDL2
###########################
include $(CLEAR_VARS)
LOCAL_MODULE := SDL2
LOCAL_SRC_FILES := $(MY_APP_SDL2_OUTPUT_PATH)/libSDL2.so
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include/SDL2
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
include $(BUILD_SHARED_LIBRARY)
###########################
# FFmpegAudioPlayer library
###########################
include $(CLEAR_VARS)
LOCAL_CFLAGS += -std=c99
LOCAL_LDLIBS += -llog -lz -lOpenSLES

LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_SRC_FILES += FFmpegAudioPlayer.c
LOCAL_SRC_FILES += FFmpegCore.c
LOCAL_SRC_FILES += OpenSL_ES_Core.c

LOCAL_STATIC_LIBRARIES := avformat avcodec swscale swresample avfilter avutil

LOCAL_MODULE := FFmpegAudioPlayer
include $(BUILD_SHARED_LIBRARY)
###########################
# MPEG-2 TS demuxer
###########################
include $(CLEAR_VARS)
LOCAL_CFLAGS += -std=c99
LOCAL_LDLIBS += -llog -lz

LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
#LOCAL_SRC_FILES += mpegts.c
LOCAL_STATIC_LIBRARIES := avformat avcodec swscale swresample avfilter avutil

LOCAL_MODULE := MPEG
include $(BUILD_SHARED_LIBRARY)
###########################
# AudioRecordPlayBack
# USE OpenSL ES API
###########################
include $(CLEAR_VARS)
LOCAL_MODULE := AudioRecordPlayBack
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := AudioRecordPlayBack.c opensl_io.c
LOCAL_LDLIBS := -llog -lOpenSLES
include $(BUILD_SHARED_LIBRARY)
###########################
# ffmpeg_mediaplayer_jni
###########################
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg_mediaplayer_jni
SDL_PATH := src/SDL2
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include/SDL2
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/player
LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(SDL_PATH)/video/android
LOCAL_CFLAGS :=
LOCAL_SRC_FILES := $(SDL_PATH)/main/android/SDL_android_main.c \
    src/player/wseemann_media_MediaPlayer.cpp \
    src/player/mediaplayer.cpp \
    src/player/ffmpeg_mediaplayer.c \
    src/player/audioplayer.c \
    src/player/videoplayer.c \
    src/player/ffmpeg_utils.c
LOCAL_STATIC_LIBRARIES := avformat avcodec swscale swresample avfilter avutil
LOCAL_SHARED_LIBRARIES := SDL2
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../ffmpeg/ffmpeg/$(TARGET_ARCH_ABI)/include
# for native audio
LOCAL_LDLIBS += -lOpenSLES -lGLESv1_CM -lGLESv2 -lz
# for logging
LOCAL_LDLIBS += -llog
LOCAL_LDLIBS += -landroid
LOCAL_LDLIBS += -ljnigraphics
include $(BUILD_SHARED_LIBRARY)
###########################
# FFmpegMediaPlayerEx
###########################
include $(CLEAR_VARS)
LOCAL_MODULE := FFmpegMediaPlayerEx
SDL_PATH := src/SDL2
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include/SDL2
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/player
LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(SDL_PATH)/video/android
LOCAL_CFLAGS :=
LOCAL_SRC_FILES := $(SDL_PATH)/main/android/SDL_android_main.c \
    src/FFmpegMediaPlayerEx/FFmpegMediaPlayer_jni.cpp \
    src/FFmpegMediaPlayerEx/mediaplayer.cpp \
    src/FFmpegMediaPlayerEx/ffmpeg_mediaplayer.c \
    src/FFmpegMediaPlayerEx/audioplayer.c \
    src/FFmpegMediaPlayerEx/videoplayer.c \
    src/FFmpegMediaPlayerEx/ffmpeg_utils.c
LOCAL_STATIC_LIBRARIES := avformat avcodec swscale swresample avfilter avutil
LOCAL_SHARED_LIBRARIES := SDL2
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../ffmpeg/ffmpeg/$(TARGET_ARCH_ABI)/include
# for native audio
LOCAL_LDLIBS += -lOpenSLES -lGLESv1_CM -lGLESv2 -lz
# for logging
LOCAL_LDLIBS += -llog
LOCAL_LDLIBS += -landroid
LOCAL_LDLIBS += -ljnigraphics
include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/cpufeatures)